package com.sanjiahantang.youjiaclient.module.login.views.impl;

import android.app.Activity;
import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.sanjiahantang.uilibrary.utils.Utils;
import com.sanjiahantang.youjiaclient.R;
import com.sanjiahantang.youjiaclient.base.BaseMvpActivity;
import com.sanjiahantang.youjiaclient.module.login.presenters.LoginPresenter;
import com.sanjiahantang.youjiaclient.module.login.views.LoginView;

/**
 * Created by zy on 2018/3/21.
 */

public class ProtectedPasswordActivity extends BaseMvpActivity<LoginView,LoginPresenter> implements LoginView, View.OnClickListener {

    private EditText editPassword,aginPassword;

    @Override
    public void showProgress() {
        super.showProgress($this);
    }

    @Override
    public LoginPresenter initPresenter() {
        return new LoginPresenter();
    }

    @Override
    public void initView() {
        setContentView(R.layout.activity_protected_password);
        findViewById(R.id.btnSubmit).setOnClickListener(this);
        findViewById(R.id.fl_Left).setOnClickListener(this);
        TextView title = (TextView) findViewById(R.id.title);
        title.setText("注册");
        editPassword = (EditText) findViewById(R.id.editPassword);
        aginPassword = (EditText) findViewById(R.id.aginPassword);
    }

    @Override
    public void initData() {

    }

    public static void startActivity(Activity context){
        context.startActivityForResult(new Intent(context,ProtectedPasswordActivity.class),PAGE_PROTECTED_PASSWORD);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.btnSubmit:
                checkValid();
                break;
            case R.id.fl_Left:
                finish();
                break;
        }
    }

    private void checkValid() {
        boolean isValid = true;
        String password = editPassword.getText().toString();
        String repeat = aginPassword.getText().toString();
        if (password.length() != 6){
            Utils.showToast($this,"请设置6位数字支付密码");
            isValid = false;
        }

        if (isValid && !TextUtils.equals(password,repeat)){
            Utils.showToast($this,"请确认支付密码");
            isValid = false;
        }

        if (isValid){
            Intent intent = new Intent();
            intent.putExtra(KEY_PARAM,password);
            setResult(RESULT_OK,intent);
            finish();
        }
    }
}
